package www.openteam.com.ui;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import www.openteam.com.R;
import www.openteam.com.tool.ToastUtil;

/**
 * Created by kylin on 2016/8/4.
 */
public class AboutFragment extends Fragment {

    private String mParam;
    @Bind(R.id.tv_content)
    TextView tv_content;
    @Bind(R.id.tv_versionName)
    TextView tv_versionName;
    public AboutFragment(){}

    @Override
    public void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null){
            mParam =getArguments().getString("key");
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_default,container,false);
    }

    @OnClick(R.id.btn_company)
    public void comAbstract(){
        Intent intent = new Intent(getActivity(),BriefIntroductionActivity.class);
        intent.putExtra("brief","companyname");
        startActivity(intent);
    }

    @OnClick(R.id.btn_erp)
    public void erpAbstract(){
        Intent intent = new Intent(getActivity(),BriefIntroductionActivity.class);
        intent.putExtra("brief","erpname");
        startActivity(intent);
    }

    @OnClick(R.id.btn_evaluate)
    public void evaAbstract(){
        Intent intent = new Intent(getActivity(),BriefIntroductionActivity.class);
        intent.putExtra("brief","evaluatename");
        startActivity(intent);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this,view);
//        System.out.println(mParam + " - 创建完毕");
        initView(view);
    }

    private void initView(View view) {
        if(TextUtils.isEmpty(mParam)){
            tv_content.setText("简介");
            PackageManager packageManager =getContext().getPackageManager();
            // getPackageName()是你当前类的包名，0代表是获取版本信息
            PackageInfo packInfo = null;
            try {
                packInfo = packageManager.getPackageInfo(getContext().getPackageName(),0);
                String version = packInfo.versionName;
                tv_versionName.setText(version);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

        }else {
            tv_content.setText(mParam);
        }

    }
}
